<!-- CommentItem.vue -->
<template>
  <div class="comment-item" :class="{ 'first-level': depth === 0 }">
    <div class="avatar-container">
      
    </div>
    <div class="comment-main">
      <!-- 评论头部 -->
      <div class="comment-header">
        <div class="author-info">
          <span class="author">{{ comment.author }}</span>
          <span v-if="isAuthor" class="badge">作者</span>
          <span class="time">{{ comment.createdAt }}</span>
        </div>
        <div v-if="depth === 0" class="title">{{ comment.content }}</div>
        <span v-else class="reply-to" v-if="comment.replyTo">回复 @{{ comment.replyTo }}</span>
      </div>

      <div class="comment-content" v-if="depth > 0">
        {{ comment.content }}
      </div>

      <div class="comment-actions">
        <button @click.stop="handleLike" class="like-btn">
          <span v-if="comment.hasLiked">❤️</span>
          <span v-else>🤍</span>
          <span class="like-count">{{ comment.likes }}</span>
        </button>
        <button @click.stop="handleReply" class="reply-btn">回复</button>
        <button v-if="isAuthor" @click.stop="handleDelete" class="delete-btn">删除</button>
      </div>

      <!-- 二级评论列表 -->
      <div class="replies" v-if="depth === 0 && comment.replies && comment.replies.length">
        <CommentItem
          v-for="reply in displayReplies"
          :key="reply.id"
          :comment="reply"
          :depth="1"
          :is-author="reply.author === currentUser"
          @reply="$emit('reply', $event)"
          @delete="$emit('delete', $event)"
        />
        
        <!-- 查看更多/收起按钮 -->
        <button v-if="showMoreButton" @click="toggleReplies" class="more-btn">
          {{ comment.expanded ? "收起回复" : `查看更多回复(${comment.replies.length - 3})` }}
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
// 脚本部分保持不变
</script>

<style scoped>
.comment-item {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.first-level {
  padding-bottom: 0;
  border-bottom: none;
}

.avatar-container {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.comment-main {
  flex: 1;
}

.comment-header {
  margin-bottom: 8px;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.author {
  font-weight: 600;
  color: #333;
  font-size: 15px;
}

.badge {
  padding: 2px 6px;
  background-color: #f0f7ff;
  color: #1890ff;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.time {
  color: #999;
  font-size: 12px;
}

.title {
  font-size: 14px;
  color: #333;
  line-height: 1.6;
}

.reply-to {
  color: #1890ff;
  font-size: 12px;
}

.comment-content {
  margin-bottom: 10px;
  font-size: 14px;
  color: #333;
  line-height: 1.6;
}

.comment-actions {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
}

.like-btn, .reply-btn, .delete-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.like-btn:hover, .reply-btn:hover, .delete-btn:hover {
  background: #f5f5f5;
  border-radius: 4px;
}

.like-count {
  font-size: 14px;
  color: #666;
}

.replies {
  margin-top: 15px;
  padding-left: 52px;
  border-left: 2px solid #eee;
}

.more-btn {
  background: none;
  border: none;
  color: #1890ff;
  cursor: pointer;
  padding: 4px 0;
  font-size: 14px;
  margin-top: 8px;
}

.more-btn:hover {
  text-decoration: underline;
}
</style>